import os
from urllib.parse import quote_plus


class Config:
    """base config"""
    DIALECT = 'mysql'
    DRIVER = 'pymysql'
    MYSQL_USERNAME = os.environ.get('MYSQL_USERNAME', 'root')
    MYSQL_PASSWORD = os.environ.get('MYSQL_PASSWORD', quote_plus('123456'))
    print(MYSQL_PASSWORD, flush=True)

    # HOST = '118.190.102.136'
    MYSQL_HOST = os.environ.get('MYSQL_HOST', 'localhost')
    MYSQL_PORT = os.environ.get('MYSQL_PORT', '3306')
    MYSQL_DATABASE = os.environ.get('MYSQL_DATABASE', 'llm_question')

    SQLALCHEMY_DATABASE_URI = '{}+{}://{}:{}@{}:{}/{}?charset=utf8mb4'.format(
        DIALECT, DRIVER, MYSQL_USERNAME, MYSQL_PASSWORD, MYSQL_HOST, MYSQL_PORT,
        MYSQL_DATABASE
    )

    SQLALCHEMY_COMMIT_ON_TEARDOWN = True
    SQLALCHEMY_TRACK_MODIFICATIONS = True
    # SQLALCHEMY_ECHO = True

    # SQLAlchemy打开SQL语句方法如下，echo = true将开启该功能
    # SQLALCHEMY_ECHO = True

    SQLALCHEMY_POOL_SIZE = 10
    SQLALCHEMY_MAX_OVERFLOW = 5

    SECRET_KEY = "IECASPROMANAGE"

    RESTFUL_JSON = dict(ensure_ascii=False)
    JSON_SORT_KEYS = False


class DevelopmentConfig(Config):
    """运行环境配置"""
    DEBUG = True


class ProductionConfig(Config):
    pass


config = {
    'development': DevelopmentConfig,
    'production': ProductionConfig
}
